package com.dl.helloworld;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;

public class FirstActivity extends BaseActivity {

    private IntentFilter intentFilter;

    private NetworkChangeReceiver networkChangeReceiver;
    private static final String TAG = FirstActivity.class.getName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first);
        Button btn = findViewById(R.id.button_1);
        ProgressBar progressBar  = findViewById(R.id.progressbar);
        intentFilter = new IntentFilter();
        intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
        networkChangeReceiver  = new NetworkChangeReceiver();
        registerReceiver(networkChangeReceiver,intentFilter);

        btn.setOnClickListener(v -> {
            Log.d(TAG, "onCreate: sendBroadcast");
            Intent intent = new Intent("com.dl.helloworld.FORCE_OFFLINE");
            sendBroadcast(intent);
        });

//        btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
////                Toast.makeText(FirstActivity.this,"click",Toast.LENGTH_SHORT).show();
////                Intent intent = new Intent(Intent.ACTION_VIEW);
////                intent.setData(Uri.parse("http://www.baidu.com"));
////                Intent intent = new Intent(Intent.ACTION_DIAL);
////                intent.setData(Uri.parse("tel:1086"));
////                startActivity(intent);
////                Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
////                String data = "Hello Sc";
////                intent.putExtra("ex",data);
////                startActivity(intent);
////                SecondActivity.actionStart(FirstActivity.this,);
//                int progress = progressBar.getProgress();
//                progress = progress + 10;
//                progressBar.setProgress(progress);
//
//
//
//            }
//        });


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(networkChangeReceiver);
    }

    class NetworkChangeReceiver extends BroadcastReceiver{

        @Override
        public void onReceive(Context context, Intent intent) {
            Toast.makeText(context,"network changes",Toast.LENGTH_SHORT).show();
        }
    }
}